package com.spring.demo.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.spring.demo.domain.mongodb.History;
import com.spring.demo.service.HistoryService;

@Aspect
@Order(1)
@Component
public class UserAspect {

	protected Logger logger = Logger.getLogger(UserAspect.class);
	
	@Autowired
	private HistoryService historyService;
	
	@Pointcut("execution(* com.spring.demo.service.UserService.findByLoginName(..))")
	public void logUser() {
		
	}
	
	@Before(value = "logUser() && args(loginName,..)")
	public void beforeLogUser(String loginName) {
		History history = new History();
		history.setLog("Login Name : " + loginName + " is Login in.");
		//historyService.saveHistory(history);
	}
	
	@AfterReturning("logUser() && args(loginName,..)")
	public void afterLogUser(String loginName) {
		History history = new History();
		history.setLog("Login Name : " + loginName + " is Login in success.");
		//historyService.insertHistory(history);
	}
}
